﻿using System;
using System.Collections.Generic;
using System.Text;
using Quanlynhasach.hethongluutru;
using Quanlynhasach.hethongxuly;
using System.Data;
using Quanlynhasach;


namespace Quanlynhasach.hethongluutru
{
    class TheLoaiDAO
    {
        public static DataTable LayDanhSachTheLoai()
        {
            string sql;
            sql = "Select * From TheLoai ";
            DataTable dt = database.ExcuQuery(sql);

            return dt;
        }

        public static String LayTenTheLoai(String mtl)
        {
            string sql;
            sql = "Select TenTheLoai From TheLoai Where MaTheLoai= " + mtl;
            DataTable dt = database.ExcuQuery(sql);
            String ten = dt.Rows[0].ItemArray[0].ToString();

            return ten;
        }

        public void ThemTheLoaiSach(TheLoaiDTO tl)
        {
            string sql;
            sql = "Insert into TheLoai(TenTheLoai) values ('"+tl.m_tenTheLoai + "')";
            database.ExcuNonQuery(sql);
        }

        public void XoaTheLoaiSach(TheLoaiDTO tl)
        {
            string sql;
            sql = "Delete From TheLoai Where MaTheLoai = "+ tl.m_maTheLoai.ToString();
            database.ExcuNonQuery(sql);
        }

        public void CapNhatTheLoaiSach(TheLoaiDTO tl)
        {
            string sql;
            sql = "Update TheLoai Set TenTheLoai='" + tl.m_tenTheLoai + "'";
            sql += " Where MaTheLoai = " + tl.m_maTheLoai.ToString();
            database.ExcuNonQuery(sql);
        }

      
    } 
}
